home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16669 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 70253.3461@compuserve.com (Larry Widing)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Mutually referring header files
  5. Date: Thu, 11 Apr 1996 17:32:42 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <316d40d9.13819600@news.compuserve.com>
  8. References: <4ked7q$8g3@dub-news-svc-1.compuserve.com>
  9. NNTP-Posting-Host: hd77-125.compuserve.com
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12. RossBoylan@aol.com (Ross Boylan) wrote:
  13.  
  14. >I have 2 classes A + B, defined in separate files.  Each refers to and
  15. >messages the other.  What is the best way to handle this?
  16.  
  17. I would make the follwoing changes to your layout:
  18.  
  19. >
  20. >1) My naive approach was
  21. >a.h----------------------------------------------------------
  22. >#ifndef ah
  23. >#define ah
  24. >#include "b.h:
  25. >class A {
  26. >public:
  27. >    void hello();
  28. >private:
  29. >    B *pB;
  30. >//etc
  31. >};
  32. #else
  33. class A;
  34. >#endif
  35. >
  36. >b.h------------------------------------------------------------
  37. >#ifndef bh
  38. >#define bh
  39. >#include "a.h"
  40. >class B{
  41. >public:
  42. >    void hello();
  43. >private:
  44. >    A *pA;
  45. >};
  46. #else
  47. class B;
  48. >#endif
  49.  
  50. This will still keep the basic definitions of the class names, without
  51. duplicating the full declartions.
  52.  
  53. Larry Widing
  54.